package com.zs.propertymanage.dataObj;

import lombok.Data;

@Data
public class R {
    private Integer code; //状态码
    private String msg;     //消息
    private Object data;     //数据对象

    private R() {
    }

    // 构造函数私有化，防止外部调用，实现单例模式
    private R(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static R build() {
        return new R();
    }

    public static R ok(String msg) {
        return new R(200, msg, null);
    }

    public static R ok(String msg, Object data) {
        return new R(200, msg, data);
    }

    public static R ok(Integer code, String msg, Object data) {
        return new R(code, msg, data);
    }

    public static R error(String msg) {
        return new R(500, msg, null);
    }

    public static R error(String msg, Object obj) {
        return new R(500, msg, obj);
    }

    public static R error(Integer code, String msg, Object data) {
        return new R(code, msg, data);
    }
}
